package commRedisRpc

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Number"
	"net/http"
)

type voType struct {
	ChannelRequestVO ChannelRequestVO
	ChannelRespondVO ChannelRespondVO
	TaskRequestVO    TaskRequestVO
	TaskRespondVO    TaskRespondVO
	OperateRequestVO OperateRequestVO
	OperateRespondVO OperateRespondVO
	RestFulRequestVO RestFulRequestVO
	RestFulRespondVO RestFulRespondVO
}

type ChannelRequestVO struct {
	Type    string      `json:"type"`
	Uuid    string      `json:"uuid"`
	Name    string      `json:"name"`
	Mode    string      `json:"mode"`
	Send    interface{} `json:"send"`
	Recv    interface{} `json:"recv"`
	Timeout int         `json:"timeout"`
}

type ChannelRespondVO struct {
	Type    string      `json:"type"`
	Uuid    string      `json:"uuid"`
	Name    string      `json:"name"`
	Mode    string      `json:"mode"`
	Send    interface{} `json:"send"`
	Recv    interface{} `json:"recv"`
	Timeout int         `json:"timeout"`
	Msg     string      `json:"msg"`
	Code    int         `json:"code"`
}

type TaskRequestVO struct {
	Uuid       string              `json:"uuid"`
	ClientName string              `json:"clientName"`
	Timeout    int                 `json:"timeout"`
	RequestVOS []*OperateRequestVO `json:"requestVOS"`
}

type TaskRespondVO struct {
	Uuid       string              `json:"uuid"`
	ClientName string              `json:"clientName"`
	Timeout    int                 `json:"timeout"`
	RespondVOS []*OperateRespondVO `json:"respondVOS"`
	Msg        string              `json:"msg"`
	Code       int                 `json:"code"`
}

type OperateRequestVO struct {
	Uuid         string                 `json:"uuid"`
	OperateMode  string                 `json:"operateMode"`
	OperateName  string                 `json:"operateName"`
	Manufacturer string                 `json:"manufacturer"`
	DeviceType   string                 `json:"deviceType"`
	DeviceName   string                 `json:"deviceName"`
	Param        map[string]interface{} `json:"param"`
	Timeout      int                    `json:"timeout"`
	Record       bool                   `json:"record"`
}

type OperateRespondVO struct {
	Uuid         string                 `json:"uuid"`
	OperateMode  string                 `json:"operateMode"`
	OperateName  string                 `json:"operateName"`
	Manufacturer string                 `json:"manufacturer"`
	DeviceType   string                 `json:"deviceType"`
	DeviceName   string                 `json:"deviceName"`
	Param        map[string]interface{} `json:"param"`
	Timeout      int                    `json:"timeout"`
	Record       bool                   `json:"record"`
	Data         map[string]interface{} `json:"data"`
	Msg          string                 `json:"msg"`
	Code         int                    `json:"code"`
}

type RestFulRequestVO struct {
	Uuid   string      `json:"uuid"`
	Method string      `json:"method"`
	Uri    string      `json:"uri"`
	Data   interface{} `json:"data"`
}

type RestFulRespondVO struct {
	Uuid   string      `json:"uuid"`
	Method string      `json:"method"`
	Uri    string      `json:"uri"`
	Data   interface{} `json:"data"`
	Msg    string      `json:"msg"`
	Code   int         `json:"code"`
}

func (e *ChannelRespondVO) New() *ChannelRespondVO {
	vo := &ChannelRespondVO{}
	vo.Code = http.StatusOK
	return vo
}

func (e *ChannelRespondVO) BindRequestVO(vo *ChannelRequestVO) {
	e.Type = vo.Type
	e.Uuid = vo.Uuid
	e.Name = vo.Name
	e.Mode = vo.Mode
	e.Send = vo.Send
	e.Recv = vo.Recv
	e.Timeout = vo.Timeout
}

func (e *ChannelRespondVO) Error(requestVO *ChannelRequestVO, msg string) *ChannelRespondVO {
	vo := &ChannelRespondVO{}
	vo.BindRequestVO(requestVO)
	vo.Code = http.StatusInternalServerError
	vo.Msg = msg
	return vo
}

func (e *ChannelRespondVO) Ok(requestVO *ChannelRequestVO) *ChannelRespondVO {
	vo := &ChannelRespondVO{}
	vo.BindRequestVO(requestVO)
	vo.Code = http.StatusOK
	return vo
}

func (e *TaskRespondVO) New() *TaskRespondVO {
	vo := &TaskRespondVO{}
	vo.RespondVOS = make([]*OperateRespondVO, 0)
	vo.Code = http.StatusOK
	return vo
}

func (e *TaskRespondVO) BuildRespondVO(operateRespondVO *OperateRespondVO, clientName string) *TaskRespondVO {
	taskRespondVO := &TaskRespondVO{}
	taskRespondVO.Uuid = operateRespondVO.Uuid
	taskRespondVO.ClientName = clientName
	taskRespondVO.Timeout = operateRespondVO.Timeout
	taskRespondVO.RespondVOS = make([]*OperateRespondVO, 0)
	taskRespondVO.RespondVOS = append(taskRespondVO.RespondVOS, operateRespondVO)
	return taskRespondVO
}

func (e *OperateRequestVO) New() *OperateRequestVO {
	vo := &OperateRequestVO{}
	vo.Param = make(map[string]interface{})
	vo.Timeout = 2000
	return vo
}

func (e *OperateRequestVO) BindRequestMap(data map[string]interface{}) {
	e.Uuid = Map.GetOrDefault(data, "uuid", "").(string)
	e.DeviceName = Map.GetOrDefault(data, "deviceName", "").(string)
	e.Manufacturer = Map.GetOrDefault(data, "manufacturer", "").(string)
	e.DeviceType = Map.GetOrDefault(data, "deviceType", "").(string)
	e.Timeout = Number.MakeInt(data["timeout"])
	e.OperateMode = Map.GetOrDefault(data, "operateMode", "").(string)
	e.OperateName = Map.GetOrDefault(data, "operateName", "").(string)
	e.Param = Map.GetOrDefault(data, "param", make(map[string]interface{})).(map[string]interface{})
	e.Record = true == data["record"]
}

func (e *OperateRespondVO) BindRespondMap(data map[string]interface{}) {
	e.Uuid = Map.GetOrDefault(data, "uuid", "").(string)
	e.DeviceName = Map.GetOrDefault(data, "deviceName", "").(string)
	e.Manufacturer = Map.GetOrDefault(data, "manufacturer", "").(string)
	e.DeviceType = Map.GetOrDefault(data, "deviceType", "").(string)
	e.Timeout = Number.MakeInt(data["timeout"])
	e.OperateMode = Map.GetOrDefault(data, "operateMode", "").(string)
	e.OperateName = Map.GetOrDefault(data, "operateName", "").(string)
	e.Param = Map.GetOrDefault(data, "param", make(map[string]interface{})).(map[string]interface{})
	e.Record = true == data["record"]
}

func (e *OperateRespondVO) BindRequestVO(vo *OperateRequestVO) {
	e.Uuid = vo.Uuid
	e.DeviceName = vo.DeviceName
	e.Manufacturer = vo.Manufacturer
	e.DeviceType = vo.DeviceType
	e.Timeout = vo.Timeout
	e.OperateMode = vo.OperateMode
	e.OperateName = vo.OperateName
	e.Param = vo.Param
	e.Record = vo.Record
}

func (e *OperateRespondVO) BindRespondVO(vo *OperateRespondVO) {
	e.Uuid = vo.Uuid
	e.DeviceName = vo.DeviceName
	e.Manufacturer = vo.Manufacturer
	e.DeviceType = vo.DeviceType
	e.Timeout = vo.Timeout
	e.OperateMode = vo.OperateMode
	e.OperateName = vo.OperateName
	e.Param = vo.Param
	e.Record = vo.Record
}

func (e *TaskRequestVO) New() *TaskRequestVO {
	vo := &TaskRequestVO{}
	vo.RequestVOS = make([]*OperateRequestVO, 0)
	return vo
}

func (e *RestFulRespondVO) BindRequestVO(vo *RestFulRequestVO) {
	e.Uuid = vo.Uuid
	e.Method = vo.Method
	e.Uri = vo.Uri
	e.Data = vo.Data
}

func (e *RestFulRespondVO) BindRespondVO(vo *RestFulRequestVO) {
	e.Uuid = vo.Uuid
	e.Method = vo.Method
	e.Uri = vo.Uri
	e.Data = vo.Data
}

func (e *RestFulRequestVO) New() *RestFulRequestVO {
	return &RestFulRequestVO{}
}
